<?php
/**
 * 由开发环境变为生产环境需要进行一些调整
 */
header("Content-Type: text/html; charset=gb2312");

// 定义旧的文件夹名和新的文件夹名
define('OLD_DIR', 'wooowang');
define('NEW_DIR', 'wooowang_pro');

/**
 * 删除文件夹和文件夹内的所有文件
 * @param $name
 */
function delFile($name){
    if(is_file($name)){
        unlink($name);
    }else if(is_dir($name)){
        $handle = opendir("$name");
        while(false !== ($item = readdir($handle))){  
            if($item != "." && $item != ".."){
                delFile("$name/$item");
            }
        }
        closedir($handle);
        rmdir($name);
    } 
}

// 判断，如果不是目录下，则直接报错
if(substr(getcwd(), -strlen(NEW_DIR)) !== NEW_DIR){
    echo "\n================ You Should change output dir to deal ================\n";
    exit;
}

// 打印开头部分
echo "\n================ Release Start ================\n\n";

// del runtime dir
// delFile('./runtime');
// echo "11:    Runtime Dir has been delete Success!\n";

// change index.php debug config
$index_dir = './public/index.php';
$index_string = str_replace("define('APP_DEBUG', true);", "", file_get_contents($index_dir));
file_put_contents($index_dir, $index_string);
echo "\n================ Config index.php ================\n\n";

echo "\n================ Release End ==================";
exit;


